﻿<Window x:Class="ETWController.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:ETWController"
        xmlns:h="clr-namespace:ETWController.Hooking"
        xmlns:ui="clr-namespace:ETWController.UI"
        MinHeight="440"
        MinWidth="640"
        Title="ETW Controller And Logger" Height="500" Width="773.5" Closing="Window_Closing">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="UI\Styles.xaml"/>
                <ResourceDictionary Source="UI\GlassButton.xaml"/>
                <ResourceDictionary Source="UI\Validation.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Menu Grid.Row="0"  DockPanel.Dock="Top">
            <MenuItem Header="Configuration">
                <MenuItem Header="Configuration" Command="{Binding Commands[Config]}"/>
                <MenuItem Header="Register ETW Provider" Command="{Binding Commands[RegisterETWProvider]}" ToolTip="Create manifest and register hook key ETW provider in system. This needs to be done only once."/>
                <MenuItem Header="Reset Configuration" Command="{Binding Commands[ConfigReset]}" ToolTip="Reset any user configured values to the defaults of ETWController in its current version. This can help to see updated settings provided by a newer version of ETWController."/>
            </MenuItem>
            <MenuItem Header="Help">
                <MenuItem Header="Command line options" Command="{Binding Commands[ShowCommandLineOptions]}"/>
                <MenuItem Header="About" Command="{Binding Commands[About]}"/>
            </MenuItem>

        </Menu>
        <StatusBar MaxHeight="100"
            HorizontalAlignment="Stretch"
            HorizontalContentAlignment="Stretch" DockPanel.Dock="Bottom"
            >
            <StatusBar.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Show Messages" Command="{Binding Commands[ShowMessages]}" />
                    <MenuItem Header="Clear Messages" Command="{Binding Commands[ClearStatusMessages]}"/>
                </ContextMenu>
            </StatusBar.ContextMenu>

            <TextBlock Text="{Binding StatusText}"
                       Foreground="{Binding StatusColor}"
                       TextWrapping="WrapWithOverflow" 
                       PreviewMouseLeftButtonUp="StatusBarClick" Padding="5">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Resources>
                            <Storyboard x:Key="flashAnimation" >
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" AutoReverse="True" Duration="0:0:0.5" RepeatBehavior="0:0:5" />
                            </Storyboard>
                        </Style.Resources>
                        <!-- <Setter Property="Visibility" Value="Hidden" /> -->
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ErrorHasOccured}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Name="flash" Storyboard="{StaticResource flashAnimation}" />
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <StopStoryboard BeginStoryboardName="flash"/>
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </StatusBar>
        <TabControl>
            <TabItem Header="Network And Capturing">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="150"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Expander Header="Capture keyboard and mouse" IsExpanded="True" Grid.Row="0" Expanded="Expander_Expanded" >
                        <Grid Height="120">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="20"/>
                                <RowDefinition Height="90"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="150" />
                                <ColumnDefinition Width="150"/>
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <CheckBox Grid.Row="0" Grid.Column="0" Content="Capture keyboard" HorizontalAlignment="Left"  VerticalAlignment="Top" IsChecked="{Binding CaptureKeyboard}" Height="15" ToolTip="Log all keyboard down events to ETW."/>
                            <CheckBox Grid.Row="0" Grid.Column="1" Content="Capture mouse clicks" HorizontalAlignment="Left"  VerticalAlignment="Top" IsChecked="{Binding CaptureMouseButtonDown}" Height="16" Grid.ColumnSpan="2" ToolTip="Log all mouse button down events to ETW."/>
                            <CheckBox Grid.Row="0" Grid.Column="3" Content="Capture mouse move"  HorizontalAlignment="Left" IsChecked="{Binding CaptureMouseMove}"  VerticalAlignment="Top" Height="15" Grid.ColumnSpan="2" ToolTip="Log all mouse move events to ETW. There can be many of them!"/>
                            <CheckBox Grid.Row="1" Grid.Column="1" Content="Take Screenshots"  HorizontalAlignment="Left" IsChecked="{Binding CaptureScreenShots}"  VerticalAlignment="Top" Height="15" Grid.ColumnSpan="2" ToolTip="Capture a screenshot at every mouse click."/>
                            <CheckBox Grid.Row="1" Grid.Column="0"  Content="Encrypt keyboard keys" IsChecked="{Binding IsKeyBoardEncrypted}" ToolTip="Enabled by default so you do not record passwords or other sensitive information by accident. Only a generic SomeKey mesage is logged if checked. But the keys F1-F10, Enter, Space, Alt, Tab, Shift and the cursor keys are still preserved." />
                            <Grid Grid.Row="2" Grid.ColumnSpan="4">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="250"/>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="150"/>
                                    <ColumnDefinition Width="250"/>
                                    <ColumnDefinition Width="50"/>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" Grid.Column="0" Content="Log Slow message when key is pressed" HorizontalAlignment="Left"  Height="28"  ToolTip="Log this message when the Slow event key was pressed."/>
                                <Button  Grid.Row="0" Grid.Column="1" Style="{StaticResource GlassButton}" Width="28" Height="23" Background="#FF1DB97A"  Content="Slow" HorizontalAlignment="Left" VerticalAlignment="Top"  Click="DefineSlowHotkeyClick" ToolTip="Define hotkey to log a Slow event with message text to the right." />
                                <TextBox Grid.Row="0" Grid.Column="2" Height="25" Width="130" TextWrapping="Wrap" Name="cSlowHotkyeTextBox" Text="{Binding SlowEventHotkey}"  IsEnabled="False"  ToolTip="Press the Slow Button to define a hotkey for the slow event."/>
                                <TextBox Grid.Row="0" Grid.Column="3" Width="240" HorizontalAlignment="Left" Height="25" Text="{Binding SlowEventMessage}"  Style="{StaticResource enableSlowMessage}" ToolTip="Log this message when the Slow event key was pressed."  />
                                <Button Grid.Row="0" Grid.Column="4" Width="50" HorizontalAlignment="Left" Height="25" IsDefault="True" Command="{Binding Commands[LogSlow]}" Content="Log" ToolTip="Log directly the slow event message to ETW."/>

                                <Label Grid.Row="1" Grid.Column="0" Content="Log Fast message when key is pressed" HorizontalAlignment="Left"  Height="28"  ToolTip="Log this message when the Fast event key was pressed."/>
                                <Button  Grid.Row="1" Grid.Column="1" Style="{StaticResource GlassButton}" Width="28" Height="23" Background="#FF1DB97A"  Content="Fast" HorizontalAlignment="Left" VerticalAlignment="Top"  Click="DefineFastHotkeyClick" ToolTip="Define hotkey to log a Fast event with message text to the right." />
                                <TextBox Grid.Row="1" Grid.Column="2" Height="25" Width="130" TextWrapping="Wrap" Name="cFastHotkeyTextBox" Text="{Binding FastEventHotkey}"  IsEnabled="False"  ToolTip="Press the Fast button to define a hotkey for the Fast event."/>
                                <TextBox Grid.Row="1" Grid.Column="3" Width="240" HorizontalAlignment="Left" Height="25" Text="{Binding FastEventMessage}"  Style="{StaticResource enableFastMessage}" ToolTip="Log this message when the Fast event key was pressed."  />
                                <Button Grid.Row="1" Grid.Column="4" Width="50" HorizontalAlignment="Left" Height="25"  Command="{Binding Commands[LogFast]}" Content="Log" ToolTip="Log directly the slow event message to ETW."/>


                                <Grid Grid.Row="2" Grid.ColumnSpan="5">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="250"/>
                                        <ColumnDefinition Width="150"/>
                                        <ColumnDefinition Width="150"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Column="0" Margin="5,0,0,0">Send captured data over network</TextBlock>
                                    <CheckBox Grid.Column="1"  Command="{Binding Commands[NetworkSendToggle]}"  Content="Start sending" IsChecked="{Binding NetworkSendEnabled}"   Margin="5,0,0,0"/>
                                </Grid>
                            </Grid>
                        </Grid>
                    </Expander>

                    <GridSplitter HorizontalAlignment="Stretch" 
                  VerticalAlignment="Top" 
                  Grid.Row="1" ResizeBehavior="PreviousAndNext"
                  Height="5" Background="#FFBCBCBC"/>
                    <ListView Grid.Row="2" ItemsSource="{Binding ReceivedMessages}" ScrollViewer.VerticalScrollBarVisibility="Visible">
                        <ListView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Clear" Click="ClearMessages"></MenuItem>
                            </ContextMenu>
                        </ListView.ContextMenu>
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Width="600"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
                </Grid>
            </TabItem>
            <TabItem Header="Trace Collection">
                <StackPanel>
                    <GroupBox>
                        <GroupBox.Header>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="25"/>
                                    <RowDefinition Height="10"/>
                                    <RowDefinition Height="25"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="450"/>
                                    <ColumnDefinition Width="180"/>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" >$FileName</Label>
                                <TextBox Grid.Row="0" Grid.Column="1"  Text="{Binding UnexpandedTraceFileName}"/>
                                <StackPanel Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" Orientation="Horizontal">
                                <CheckBox Margin="5"  IsChecked="{Binding AppendIndexToOutputFileName}" Content="Append Index"
                                          ToolTip="Append a counter to the output file name to prevent overwriting old trace data by accident in the current trace session." />
                                    <TextBox Margin="5">
                                        <TextBox.Text>
                                            <Binding Path="TraceFileCounter" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" >
                                                <Binding.ValidationRules>
                                                    <ui:PortnumberValidator Min="1" Max="100"/>
                                                </Binding.ValidationRules>
                                            </Binding>
                                        </TextBox.Text>
                                    </TextBox>
                                </StackPanel>

                                <TextBlock Grid.Row="2" Grid.Column ="0" Margin="5,0,0,0">Local Host</TextBlock>
                                <CheckBox Grid.Row="2"  Grid.Column="1" Content="Enable" Margin="5,0,0,0" Width="70" IsChecked="{Binding LocalTraceEnabled}"/>
                            </Grid>
                        </GroupBox.Header>
                        <ui:TraceControl DataContext="{Binding LocalTraceSettings}"></ui:TraceControl>
                    </GroupBox>
                    <GroupBox>
                        <GroupBox.Header>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="250"/>
                                    <ColumnDefinition Width="150"/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock>Server</TextBlock>
                                    <TextBlock Grid.Column ="0" Text="{Binding Host}" Margin="5,0,0,0"/>
                                    <TextBlock Grid.Column ="0" Text="{Binding WCFPort}" Margin="5,0,0,0"/>
                                </StackPanel>
                                <CheckBox Grid.Column="1" Content="Enable" Margin="5,0,0,0" Width="70" IsChecked="{Binding ServerTraceEnabled}"/>
                            </Grid>
                        </GroupBox.Header>
                        <ui:TraceControl  DataContext="{Binding ServerTraceSettings}"></ui:TraceControl>
                    </GroupBox>
                    <StackPanel Margin="0,5,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button IsDefault="True" Content="_Start" Width="80" Command="{Binding Commands[StartTracing]}" Margin="10,0,0,0"></Button>
                        <Button Content="S_top" Width="80"  Command="{Binding Commands[StopTracing]}" Margin="10,0,0,0"></Button>
                        <Button Content="Can_cel" Width="80" Command="{Binding Commands[CancelTracing]}" Margin="10,0,0,0"/>
                    </StackPanel>
                </StackPanel>
            </TabItem>
            <TabItem Name="cTraceSessionsTab"  Header="Trace Sessions" GotFocus="TraceRefreshSelected">
                <DockPanel>
                    <Button Width="50" DockPanel.Dock="Top" Command="{Binding Commands[TraceRefresh]}">Refresh</Button>
                    <StackPanel DockPanel.Dock="Top">
                        <Expander Header="Local" IsExpanded="True">
                            <ListBox Height="150" ItemsSource="{Binding TraceSessions}">
                            </ListBox>
                        </Expander>
                    </StackPanel>
                    <StackPanel DockPanel.Dock="Bottom">
                        <Expander IsExpanded="True">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="Remote Host: "/>
                                    <Label Content="{Binding TraceServiceUrl}"/>
                                </StackPanel>
                            </Expander.Header>
                            <ListBox  Height="150" ItemsSource="{Binding ServerTraceSessions}"></ListBox>
                        </Expander>
                    </StackPanel>
                </DockPanel>
            </TabItem>
        </TabControl>

    </DockPanel>
</Window>
